package cn.changshengjue.dakong;


import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import cn.changshengjue.dakong.command.CommandHandler;
import cn.changshengjue.dakong.config.cfg;
import cn.changshengjue.dakong.listener.ExamplesListener;
import cn.changshengjue.dakong.utils.TheOriginalCheckUtil;

public final class main extends JavaPlugin {
	private static main instance;
	private static CommandHandler commandHandler;
	public static boolean startFail;
	public static String version;

	static {
		main.startFail = false;
	}

	public static void setCommandHandler(CommandHandler commandHandler) {
		main.commandHandler = commandHandler;
	}


	public static main getInstance() {
		return instance;
	}

	public static CommandHandler getCommandHandler() {
		return commandHandler;
	}

	@Override
	public void onEnable() {
		version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
		instance = this;
		TheOriginalCheckUtil.theOriginalCheck();
		saveDefaultConfig();
		saveDefaultResource("setting.yml");
		saveDefaultResource("item.yml");
		cfg.loadConfig();
		main.getInstance().getServer().getPluginManager().registerEvents(new ExamplesListener(), main.getInstance());
		commandHandler = new CommandHandler("dk");
	}


	@SuppressWarnings("unused")
	private void saveDefaultResource(String name) {
		File configFile = new File(this.getDataFolder(), name);
		if (!configFile.exists()) {
			saveResource(name, false);
		}
	}
}
